package com.fxx.face.http.utils;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

import java.util.List;
import java.util.Map;

/**
 * @ProjectName: HttpRequestLibs
 * @Package: com.fxx.http.libs.utils
 * @ClassName: LoggerUtil
 * @Description: Log打印
 * @Author: 付小歆
 * @CreateDate: 2021/12/9 11:07
 */
public class LoggerUtil {

    /**
     * 初始化， 在项目的Application中调用
     */
    public static void initLogger(){
        FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
                .showThreadInfo(true)
                .methodCount(3)
                .methodOffset(3)
                .tag("Fxx")
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
    }


    /**
     * 是否开发模式，正式环境请设置为 false
     */
    private final static boolean isDebug = true;

    public static void d(String msg) {
        if (isDebug)
            Logger.d(msg);
    }

    public static void e(String msg) {
        if (isDebug)
            Logger.e(msg);
    }

    public static void w(String msg) {
        if (isDebug)
            Logger.w(msg);
    }

    public static void v(String msg) {
        if (isDebug)
            Logger.v(msg);
    }

    public static void wtf(String msg) {
        if (isDebug)
            Logger.wtf(msg);
    }


    /**
     * 打印json格式
     * @param json
     */
    public static void json(String json) {
        if (isDebug)
            Logger.json(json);
    }

    /**
     * 打印xml
     * @param xml
     */
    public static void xml(String xml){
        if (isDebug)
            Logger.xml(xml);
    }

    /**
     * 打印异常
     * @param e
     * @param msg
     */
    public static void exception(Exception e,String msg){
        if (isDebug)
            Logger.e(e,msg);
    }

    /**
     * 打印List
     * @param list
     */
    public static void list(List<Object> list){
        if (isDebug)
            Logger.d(list);
    }

    /**
     * 打印Map
     * @param map
     */
    public static void map(Map<String,Object> map){
        if (isDebug)
            Logger.d(map);
    }
}
